package com.higgins.client.agentapp.tabs;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.higgins.client.GreetingService;
import com.higgins.client.GreetingServiceAsync;
import com.higgins.client.agentapp.components.JobSiteColumns;
import com.higgins.client.agentapp.components.JobSiteTable;
import com.higgins.client.agentapp.service.AgentAppService;
import com.higgins.client.agentapp.service.AgentAppServiceAsync;
import com.higgins.client.agentapp.settingstabs.AgencyTab;
import com.higgins.client.agentapp.settingstabs.AgentTab;

public class SettingsTab extends VerticalPanel {
	private final AgentAppServiceAsync agentAppService = GWT
		.create(AgentAppService.class);
	private TabPanel tabPanel;
	private JobSitesTab jobSitesTab;
	private AgencyTab agencyTab;
	private AgentTab agentTab;
	private boolean firstRun = true;
	
	public SettingsTab()	{
	}
	public void update()	{
		if (firstRun)
			initialise();
		else
			refresh();
	}
	
	public void initialise()	{
		setSize("200em","100em");
		tabPanel = new TabPanel();
		add(tabPanel);
		tabPanel.setSize("200em","100em");
		
		jobSitesTab = new JobSitesTab();
		tabPanel.add(jobSitesTab, "Job Sites");
		jobSitesTab.update();
		tabPanel.selectTab(0);

		agencyTab = new AgencyTab();
		tabPanel.add(agencyTab, "Agency");
		
		agentTab = new AgentTab();
		tabPanel.add(agentTab, "Agent");
		
		tabPanel.addSelectionHandler(new SelectionHandler<Integer>()    {

			@Override
			public void onSelection(SelectionEvent<Integer> event) {
				int selection = event.getSelectedItem();
				
				switch (selection)	{
				case 0:
					jobSitesTab.update();
					break;
				case 1:
					agencyTab.update();
					break;
				case 2:
					agentTab.update();
					break;
				case 3:
//					coveringLetterTab.update();
					break;
				}
			}
		});

		firstRun = false;
	}
	public void refresh()	{
		
	}

}
